package com.SMP.controller.meet_room;

import com.SMP.model.MeetSubscribe;
import com.SMP.model.Msg;
import com.SMP.service.meet_room.MeetSubscribeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.List;

@Controller
public class MeetSubscribeConfigController {

    /**
     * @author SY
     */
    @Autowired
    MeetSubscribeService meetSubscribeService;

    /**
     * @author SY
    //	 * @param 添加会议预约
     * */
    @RequestMapping("/addMeeting")
    @ResponseBody
    public Msg addMeetSubscribe(@Valid MeetSubscribe meetSubscribe){
        int a = meetSubscribeService.addMeetSubscribe(meetSubscribe);
        if (a==1) {
            return Msg.success();
        } else {
            return Msg.fail();
        }
    }
    /**
     * @author SY
    //	 * @param 修改会议预约
     * */
    @RequestMapping("/updMeeting")
    @ResponseBody
    public Msg updMeetSubscribe(@Valid MeetSubscribe meetSubscribe) {
        int a=meetSubscribeService.updManager(meetSubscribe);
        if (a==1) {
            return Msg.success();
        } else {
            return Msg.fail();
        }
    }
    /**
     * @author SY
    //	 * @param 查询所有会议预约
     * */
    @RequestMapping("/selAllMeeting")
    @ResponseBody
    public Msg selAllMeetSubscribe(@RequestParam(value = "pn" ) Integer pn) {
        PageHelper.startPage(pn, 10);
        List<MeetSubscribe> list=meetSubscribeService.selAllMeetSubscribe();
        PageInfo<MeetSubscribe> page = new PageInfo<MeetSubscribe>(list,  5);
        return Msg.success().add("pageInfo", page);
    }
    /**
     * @author SY
    //	 * @param 查询单个会议预约
     * */

    @RequestMapping("/selMeeting")
    @ResponseBody
    public Msg selMeetSubscribe(@RequestParam(value="id" ,defaultValue = "1")String id) {
        MeetSubscribe meetSubscribe=meetSubscribeService.selMeetSubscribe(id);

        return Msg.success().add("meetSubscribe",meetSubscribe);
    }
    /**
     * @author SY
    //	 * @param 删除单个会议预约
     * */
    @RequestMapping("/delMeeting")
    @ResponseBody
    public Msg delMeetSubscribe(@RequestParam(value="subscribe_room_id" ,defaultValue = "1")String subscribe_room_id) {

        int a=meetSubscribeService.delMeetSubscribe(subscribe_room_id);
        if (a==1) {
            return Msg.success();
        } else {
            return Msg.fail();
        }
    }
}


